<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" :class="method==='view'?'readonly':''"  :disabled="method==='view'" @keyup.enter.native="doSubmit()"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="指标名称" prop="name"
                :rules="[
                 ]">
              <el-input v-model="inputForm.name" placeholder="请填写指标名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="类别" prop="checkCategory"
                :rules="[
                 ]">
                <el-select v-model="inputForm.checkCategory" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('basicdata_category')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="计量单位" prop="checkUnit"
                :rules="[
                 ]">
                <el-select v-model="inputForm.checkUnit" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('basicdata_symbol_measure')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="上限判断符号" prop="checkJudgeSymbol"
                :rules="[
                 ]">
                <el-select v-model="inputForm.checkJudgeSymbol" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('basicdata_symbol')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="下限判断符号" prop="checkDownJudgeSymbol"
                :rules="[
                 ]">
                 <el-select v-model="inputForm.checkDownJudgeSymbol" placeholder="请选择"  style="width: 100%;">
                           <el-option
                             v-for="item in $dictUtils.getDictList('basicdata_symbol')"
                             :key="item.value"
                             :label="item.label"
                             :value="item.value">
                           </el-option>
                       </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="上限" prop="checkUp"
                :rules="[
                 ]">
              <el-input v-model="inputForm.checkUp" placeholder="请填写上限"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="上极限" prop="checkLimit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.checkLimit" placeholder="请填写上极限"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="下限" prop="checkDown"
                :rules="[
                 ]">
              <el-input v-model="inputForm.checkDown" placeholder="请填写下限"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="下极限" prop="checkDownLimit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.checkDownLimit" placeholder="请填写下极限"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否异常" prop="isnormal"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.isnormal">
                        <el-radio v-for="item in $dictUtils.getDictList('true_false')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
         <el-col :span="12">
            <el-form-item label="异常等级" prop="normalLevel" :rules="[
                   ]">
              <el-select v-model="inputForm.normalLevel" placeholder="请选择" style="width: 100%;">
                <el-option v-for="item in $dictUtils.getDictList('abnormal_level')" :key="item.value" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        <el-col :span="12">
            <el-form-item label="是否手动" prop="checkJudge"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.checkJudge">
                        <el-radio v-for="item in $dictUtils.getDictList('true_false')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="点检标准" prop="checkContent"
                :rules="[
                 ]">
              <el-input v-model="inputForm.checkContent" placeholder="请填写点检标准"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="输入" prop="input"
                :rules="[
                 ]">
              <el-input v-model="inputForm.input" placeholder="请填写输入"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button v-if="method === 'add'" type="primary" @click="continueDoSubmit()">继续添加</el-button>
      <el-button @click="visible = false">关闭</el-button>
      <el-button v-if="method !== 'view'" type="primary" @click="doSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        oldInputForm: '',
        inputForm: {
          id: '',
          name: '',
          checkCategory: '',
          checkUnit: '',
          checkJudgeSymbol: '',
          checkDownJudgeSymbol: '',
          checkUp: '',
          normalLevel: '',
          checkLimit: '',
          checkDown: '',
          checkDownLimit: '',
          isnormal: '',
          checkJudge: '',
          checkContent: '',
          input: '',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, obj) {
        this.method = method
        if (method === 'add') {
          this.title = `新建点检异常附表`
        } else if (method === 'edit') {
          this.title = '修改点检异常附表'
        } else if (method === 'view') {
          this.title = '查看点检异常附表'
        }
        this.visible = true
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.id = ''
          this.oldInputForm = ''
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.oldInputForm = obj
            this.inputForm = JSON.parse(JSON.stringify(obj))
          }
        })
      },
   // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.visible = false
          }
        })
      },
      continueDoSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.$refs['inputForm'].resetFields()
          }
        })
      }
    }
  }
</script>
